﻿#region Header
// Copyright 2007-2011, Jerónimo Milea
// 
// This file is part of NetJsWire.
// 
//     NetJsWire is free software: you can redistribute it and/or modify
//     it under the terms of the GNU General Public License as published by
//     the Free Software Foundation, either version 3 of the License, or
//     (at your option) any later version.
// 
//     NetJsWire is distributed in the hope that it will be useful,
//     but WITHOUT ANY WARRANTY; without even the implied warranty of
//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//     GNU General Public License for more details.
// 
//     You should have received a copy of the GNU General Public License
//     along with NetJsWire.  If not, see <http://www.gnu.org/licenses/>.
#endregion

using System.ComponentModel;

namespace NetJsWire.Widgets.Ui.Table
{
    /// <summary>
    ///   This class encapsulates the user interface of an Ext.grid.GridPanel.
    ///   Methods of this class may be used to access user interface elements to enable special display effects. Do not change the DOM structure of the user interface.
    /// </summary>
    [ TypeConverter( typeof (ExpandableObjectConverter) ) ]
    public class GridView
    {
        #region Config Options

        private string emptyText = string.Empty;

        /// <summary>
        ///   True to auto expand the columns to fit the grid when the grid is created.
        /// </summary>
        [DefaultValue( false )]
        public bool AutoFill { get; set; }

        /// <summary>
        ///   True to defer emptyText being applied until the store's first load.
        /// </summary>
        [DefaultValue( false )]
        public bool DeferEmptyText { get; set; }

        /// <summary>
        ///   Default text to display in the grid body when no rows are available (defaults to '').
        /// </summary>
        [ DefaultValue( ( string ) null ) ]
        public string EmptyText
        {
            get { return emptyText; }
            set { emptyText = value; }
        }

        /// <summary>
        ///   True to add a second TR element per row that can be used to provide a row body that spans beneath the data row. Use the getRowClass method's rowParams config to customize the row body.
        /// </summary>
        [DefaultValue( false )]
        public bool EnableRowBody { get; set; }

        /// <summary>
        ///   True to auto expand/contract the size of the columns to fit the grid width and prevent horizontal scrolling.
        /// </summary>
        [DefaultValue( false )]
        public bool ForceFit { get; set; }

        #endregion Config Options

        #region Public propertys

        private string columnsText;

        private int scrollOffset = 19;
        private string sortClasses = "['sort-asc', 'sort-desc']";

        /// <summary>
        ///   The text displayed in the "Columns" menu item.
        /// </summary>
        [ DefaultValue( ( string ) null ),
          Description( "The text displayed in the \"Columns\" menu item.\nLeave it empty to let localization handle it."
              ) ]
        public string ColumnsText
        {
            get { return columnsText; }
            set
            {
                columnsText = value;
                if ( value == "" )
                {
                    columnsText = null;
                }
            }
        }

        /// <summary>
        ///   The amount of space to reserve for the scrollbar (defaults to 19 pixels).
        /// </summary>
        [ DefaultValue( 19 ), Description( "The amount of space to reserve for the scrollbar (defaults to 19 pixels)." )
        ]
        public int ScrollOffset
        {
            get { return scrollOffset; }
            set { scrollOffset = value; }
        }

        /// <summary>
        ///   The text displayed in the "Sort Ascending" menu item.
        /// </summary>
        [DefaultValue( ( string ) null ), Description( "The text displayed in the \"Sort Ascending\" menu item.\r\nLeave it empty to let localization handle it." )]
        public string SortAscText { get; set; }

        /// <summary>
        ///   The CSS classes applied to a header when it is sorted. (defaults to ["sort-asc", "sort-desc"]).
        /// </summary>
        [ DefaultValue( "['sort-asc', 'sort-desc']" ),
          Description( "The CSS classes applied to a header when it is sorted. (defaults to ['sort-asc', 'sort-desc'])."
              ) ]
        public string SortClasses
        {
            get { return sortClasses; }
            set { sortClasses = value; }
        }

        /// <summary>
        ///   The text displayed in the "Sort Descending" menu item.
        /// </summary>
        [DefaultValue( ( string ) null ), Description( "The text displayed in the \"Sort Descending\" menu item.\nLeave it empty to let localization handle it." )]
        public string SortDescText { get; set; }

        #endregion Public propertys

        /// <summary>
        ///   Deafault constructor.
        /// </summary>
        public GridView()
        {
        }

        /// <summary>
        ///   Construct a view from an existing view.
        /// </summary>
        /// <param name = "view">The view to clone.</param>
        public GridView( GridView view )
        {
            AutoFill = view.AutoFill;
            DeferEmptyText = view.DeferEmptyText;
            EmptyText = view.EmptyText;
            EnableRowBody = view.EnableRowBody;
            ForceFit = view.ForceFit;
            ColumnsText = view.ColumnsText;
            SortAscText = view.SortAscText;
            SortClasses = view.SortClasses;
            SortDescText = view.SortDescText;
        }

        public override string ToString()
        {
            return GetType().Name;
        }
    }
}